﻿// Decompiled with JetBrains decompiler
// Type: Netick.Unity.NetworkEventsListener
// Assembly: Netick.Unity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E128C7FD-39ED-4452-86AC-6EC748457030
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.xml

using System;
using System.Collections.Generic;

#nullable disable
namespace Netick.Unity;

public abstract class NetworkEventsListener : NetickBaseBehaviour
{
  public NetworkSandbox Sandbox { get; internal set; }

  internal NetworkObject Object { get; private set; }

  internal void Init(NetworkSandbox sandbox, NetworkObject obj)
  {
    this.Sandbox = sandbox;
    this.Object = obj;
  }

  /// <summary>
  /// Called on the server when a client tries to connect. Use <paramref name="request" /> to decide whether or not to allow this client to connect.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="request"></param>
  public virtual void OnConnectRequest(NetworkSandbox sandbox, NetworkConnectionRequest request)
  {
  }

  /// <summary>
  /// Called on the client when the connection to the server was refused, or simply failed.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="reason"></param>
  public virtual void OnConnectFailed(NetworkSandbox sandbox, ConnectionFailedReason reason)
  {
  }

  /// <summary>Called to read inputs.</summary>
  /// <param name="sandbox"></param>
  public virtual void OnInput(NetworkSandbox sandbox)
  {
  }

  /// <summary>Called when Netick has been started.</summary>
  /// <param name="sandbox"></param>
  public virtual void OnStartup(NetworkSandbox sandbox)
  {
  }

  /// <summary>Called when Netick has been shut down.</summary>
  /// <param name="sandbox"></param>
  public virtual void OnShutdown(NetworkSandbox sandbox)
  {
  }

  /// <summary>
  /// Called when a sandbox visibility changes. Use Sandbox.IsVisible to find if the sandbox is visible or not.
  /// </summary>
  /// <param name="sandbox"></param>
  public virtual void OnVisibilityChanged(NetworkSandbox sandbox)
  {
  }

  /// <summary>
  /// Called on both the client and the server when a scene load/unload operation was started.
  /// </summary>
  /// <param name="sandbox"></param>
  public virtual void OnSceneOperationBegan(
    NetworkSandbox sandbox,
    NetworkSceneOperation sceneOperation)
  {
  }

  /// <summary>
  /// Called on both the client and the server when a scene load/unload operation finished.
  /// </summary>
  /// <param name="sandbox"></param>
  public virtual void OnSceneOperationDone(
    NetworkSandbox sandbox,
    NetworkSceneOperation sceneOperation)
  {
  }

  /// <summary>
  /// Called on the client when connection to the server has been initiated.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="server"></param>
  public virtual void OnConnectedToServer(NetworkSandbox sandbox, NetworkConnection server)
  {
  }

  /// <summary>
  /// Called on the client when connection to the server ended, or when a network error caused the disconnection.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="server"></param>
  public virtual void OnDisconnectedFromServer(
    NetworkSandbox sandbox,
    NetworkConnection server,
    TransportDisconnectReason transportDisconnectReason)
  {
  }

  /// <summary>
  /// Called on when a specific player has joined the game. This is synced to all clients, including late-joiners..
  /// </summary>
  public virtual void OnPlayerJoined(NetworkSandbox sandbox, NetworkPlayerId player)
  {
  }

  /// <summary>
  /// Called on when a specific player has left the game. This is synced to all clients, including late-joiners..
  /// </summary>
  public virtual void OnPlayerLeft(NetworkSandbox sandbox, NetworkPlayerId player)
  {
  }

  /// <summary>
  /// Called when a network object has been created/initialized.
  /// </summary>
  public virtual void OnObjectCreated(NetworkObject entity)
  {
  }

  /// <summary>
  /// Called when a network object has been destroyed/recycled.
  /// </summary>
  public virtual void OnObjectDestroyed(NetworkObject entity)
  {
  }

  public virtual void OnMatchListUpdate(NetworkSandbox sandbox, List<Session> sessions)
  {
  }

  public virtual void OnMatchCreated(NetworkSandbox sandbox)
  {
  }

  public virtual unsafe void OnDataReceived(
    NetworkSandbox sandbox,
    NetworkConnection sender,
    byte id,
    byte* data,
    int length,
    TransportDeliveryMethod transportDeliveryMethod)
  {
  }

  /// <summary>
  /// Called on the server when a specific client has connected.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="client"></param>
  [Obsolete("This method will be removed. Use OnPlayerJoined instead.")]
  public virtual void OnClientConnected(NetworkSandbox sandbox, NetworkConnection client)
  {
  }

  /// <summary>
  /// Called on the server when a specific client has disconnected.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="client"></param>
  [Obsolete("This method will be removed. Use OnPlayerLeft instead.")]
  public virtual void OnClientDisconnected(
    NetworkSandbox sandbox,
    NetworkConnection client,
    TransportDisconnectReason transportDisconnectReason)
  {
  }

  /// <summary>
  /// Called on the server when a specific player has connected.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="client"></param>
  [Obsolete("This method will be removed. Use OnPlayerJoined instead.")]
  public virtual void OnPlayerConnected(NetworkSandbox sandbox, NetworkPlayer player)
  {
  }

  /// <summary>
  /// Called on the server when a specific player has disconnected.
  /// </summary>
  /// <param name="sandbox"></param>
  /// <param name="client"></param>
  [Obsolete("This method will be removed. Use OnPlayerLeft instead.")]
  public virtual void OnPlayerDisconnected(
    NetworkSandbox sandbox,
    NetworkPlayer player,
    TransportDisconnectReason transportDisconnectReason)
  {
  }

  /// <summary>
  /// Called on both the client and the server when the scene has been loaded.
  /// </summary>
  /// <param name="sandbox"></param>
  [Obsolete("This method will be removed. Use OnSceneLoadBegan instead.")]
  public virtual void OnSceneLoaded(NetworkSandbox sandbox)
  {
  }

  /// <summary>
  /// Called on both the client and the server before beginning to load the new scene.
  /// </summary>
  /// <param name="sandbox"></param>
  [Obsolete("This method will be removed. Use OnSceneLoadDone instead.")]
  public virtual void OnSceneLoadStarted(NetworkSandbox sandbox)
  {
  }

  private void OnDestroy() => this.Sandbox?.Events.Unsubscribe(this);

  public void UnlinkFromNetick() => this.Sandbox.Events.Unsubscribe(this);
}
